package com.tingyun.sign.core.repository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import com.tingyun.sign.core.entity.ScUCompanyUserBean;

@Repository("companyUserDao")
public interface CompanyUserDao extends PagingAndSortingRepository<ScUCompanyUserBean, Integer>, JpaSpecificationExecutor<ScUCompanyUserBean> {

	/**
	 * 客户签到
	 * @param bean
	 * @return
	 */
	@Modifying
	@Query(value="update ScUCompanyUserBean t set t.isSigned = 1, t.muser = :muser, t.mtime = sysdate where t.id=:id")
	Integer signIn( @Param("id")Long id,@Param("muser")Long muser);

	@Modifying
	@Query(value="update ScUCompanyUserBean t set t.activityId = :activityId, t.userName = :userName,t.companyName = :companyName,t.userLevel = :userLevel,t.orderType = :orderType,t.expectSignTime = :expectSignTime,t.remark = :remark,t.muser = :muser, t.mtime = sysdate where t.status=0 and t.id=:id")
	Integer updateUser(@Param("id")Long id, @Param("userName")String userName, @Param("companyName")String companyName,
			@Param("activityId")Long activityId, @Param("userLevel")String userLevel, @Param("remark")String remark, @Param("muser")Long muser, @Param("orderType")Integer orderType,@Param("expectSignTime")Integer expectSignTime);

	@Modifying
	@Query(value="update ScUCompanyUserBean t set t.status = 1, t.muser = :muser, t.mtime = sysdate where t.id=:id")
	void deleteUser(@Param("id")Long id, @Param("muser")Long muser);

	@Query(value = "select t from ScUCompanyUserBean t where t.id in (:userIds) order by id desc")
	List<ScUCompanyUserBean> findUsersByIds(@Param("userIds")List<Long> userIds);

	@Query(value = "select t from ScUCompanyUserBean t where t.id in (:acIds) order by id desc")
	public List<ScUCompanyUserBean> findByIds(@Param("acIds")List<Long> acIds);
	
	@Query(value = "select t from ScUCompanyUserBean t where t.id = :id order by id desc")
	ScUCompanyUserBean findCompanyUser(@Param("id")Long id);

}
